/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.txt.access.capability.finder.test;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 *
 * @author seccia
 */
public class MatchTestHelper {

    private static String VECTOR_TEST_SEP = "::";
    private static FileInputStream fstream;
    private static DataInputStream in;

    public static ArrayList<MatchTest> readMatchTestFromFile(String path)
            throws FileNotFoundException, IOException{

        ArrayList<MatchTest> mts = new ArrayList<MatchTest>();

        fstream = new FileInputStream(path);

        in = new DataInputStream(fstream);

        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        String testLine[];
        String line = "";
        
        while ((line = br.readLine()) != null){
            if(line.startsWith("#")){
                continue;
            }
            testLine = line.split(VECTOR_TEST_SEP);
            try {
                MatchTest test = new MatchTest();
                test.setTopic(testLine.length > 0 ? testLine[0] : "");
                test.setResourceID(testLine.length > 1 ? testLine[1] : "");
                mts.add(test);
            } 
            catch (Exception e) {
                System.err.println("Exception: " + e.getMessage());
            }
        }
        in.close();
        return mts;
    }
}
